package ajax17;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.mysql.jdbc.Driver;

public class CopyOfDBtest {

	public static void main(String[] args) {
		PreparedStatement pstmt = null;
		Connection conn = null;
		
		
		try {
			// 1
			DriverManager.registerDriver(new Driver());
			// 2
			conn = DriverManager.getConnection(
			"jdbc:mysql://j.snpy.org/j102", "jstu", "abc123");
			String sql = "select * from users";
			pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next()) {
				String userid = rs.getString("id");
				String nickname = rs.getString("nickname");
				String password = rs.getString("password");
				String email = rs.getString("email");
				System.out.println(userid+"/"+nickname+"/"+password+"/"+email);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				if (conn != null && pstmt != null) {
					pstmt.close();
					conn.close();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
